<?php

class Core_Backend_Component_Design_View_Page_Position_Create extends Core_Backend_Share_View_Form {

    protected function initialize(){
        parent::initialize();
        $this->setTemplatePath('edit');
    }

    protected function buildToolbar($toolbar){
    	$group = $toolbar->createGroup('back');
        $group->addLink($this->getHistoryUrl('design/page_position/index'), $this->__('share.button.back'));
        $group = $toolbar->createGroup('save');
        $group->addButton($this->__('share.button.apply'))
        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(NULL, 'apply')."')");
        $group->addButton($this->__('share.button.save'))
        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(NULL, 'save')."')");
        parent::buildToolBar($toolbar);
    }

    protected function buildForm($form){
    	$entity = $this->getModel(NULL);
        $form->setAction($this->getUrl())
                ->setId('position_form')
                ->addHiddenField('id', 'position[id]')
                ->addHiddenField('area_id', 'position[area_id]', $this->getSession()->get('managed_area_id'));
        $form->addTextboxField($this->__('share.label.code'), 'code', "position[code]", TRUE)
             	->addRequiredRule();        
        $form->addTextboxField($this->__('share.label.name'), 'name', "position[name]", TRUE)
             	->addRequiredRule();
        $form->addSelectField($this->__('design.label.page_theme'), 'page_theme_id', "position[page_theme_id]")
                ->setOption('--', '')
                ->bindData($this->getPageThemes(), 'title', 'id');
        $form->addSelectField($this->__('design.label.page_template'), 'page_template_id', "position[page_template_id]", TRUE)
             	->addRequiredRule();
        $form->addBooleanField($this->__('share.label.enable'), 'enabled', 'position[enabled]');
        if(!is_null($entity)){
            $form->bindData($entity->getAllData());
        }
        $this->getTemplate()->assign('page_templates', $this->getPageTemplates());
        parent::buildForm($form);
    }
}